package org.yierge.crm.ssm.plus.admins.admin.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.yierge.crm.ssm.plus.admins.admin.pojo.param.UserRegParam;
import org.yierge.crm.ssm.plus.admins.admin.pojo.param.UserUpdateParam;
import org.yierge.crm.ssm.plus.common.web.JsonResult;

import javax.validation.Valid;

@Slf4j
@RestController(value = "admin_userController")
@RequestMapping("/account/admin")
@Validated
@Api(tags = "2.1 二级管理员用户管理模块")
public class UserController {

    public UserController() {
        log.debug("创建二级管理员控制器类对象：UserController");
    }


    // TODO 完成查询角色列表功能，只能查询角色等级比自己低的角色
    @GetMapping("/roles")
    @PreAuthorize("hasAuthority('/account/admin/roles')")
    @ApiOperation("查询角色列表")
    @ApiOperationSupport(order = 301)
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value = "页码", defaultValue = "1", dataType = "long"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部时，此参数值应为all"),
            @ApiImplicitParam(name = "roleId", value = "角色ID", defaultValue = "1", dataType = "Long"),
    })
    public JsonResult list(Integer page, String queryType, Long roleId){



        return JsonResult.ok();
    }
    // TODO

    // TODO 完成注册功能
    @GetMapping("/reg")
    @PreAuthorize("hasAuthority('/account/admin/reg')")
    @ApiOperation("注册")
    @ApiOperationSupport(order = 302)
    public JsonResult reg(@Valid UserRegParam userRegParam){



        return JsonResult.ok();
    }
    // TODO


    // TODO 展示用户列表，只能查询角色等级比自己低的用户
    @GetMapping("/userList")
    @PreAuthorize("hasAuthority('/account/admin/userList')")
    @ApiOperation("查询用户列表")
    @ApiOperationSupport(order = 303)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "Integer"),
            @ApiImplicitParam(name = "roleId", value = "角色ID", defaultValue = "1", dataType = "Long"),
    })
    public JsonResult list(Integer page, Long roleId){



        return JsonResult.ok();
    }
    // TODO

    // TODO 启用用户
    @PostMapping("/{id:[0-9]+}/enable")
    @PreAuthorize("hasAuthority('/account/admin/enable')")
    @ApiOperation("启用用户")
    @ApiOperationSupport(order = 304)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "long")
    })
    public JsonResult setEnable(@PathVariable Long id){



        return JsonResult.ok();
    }
    // TODO

    // TODO 禁用用户
    @PostMapping("/{id:[0-9]+}/disable")
    @PreAuthorize("hasAuthority('/account/admin/enable')")
    @ApiOperation("禁用用户")
    @ApiOperationSupport(order = 305)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "long")
    })
    public JsonResult setDisable(@PathVariable Long id){



        return JsonResult.ok();
    }
    // TODO

    // TODO 修改用户
    @GetMapping("/{id:[0-9]+}/update")
    @PreAuthorize("hasAuthority('/account/admin/update')")
    @ApiOperation("修改用户数据")
    @ApiOperationSupport(order = 306)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", defaultValue = "1", dataType = "long")
    })
    public JsonResult update(@Valid UserUpdateParam userUpdateParam){



        return JsonResult.ok();
    }
    // TODO

    // TODO 密码赋初值
    @GetMapping("/{id:[0-9]+}/passwordReset")
    @PreAuthorize("hasAuthority('/account/admin/update')")
    @ApiOperation("一键修改用户密码")
    @ApiOperationSupport(order = 307)
    public JsonResult passwordReset(){



        return JsonResult.ok();
    }
    // TODO

}
